//
//  kCommonDefines.swift
//  kExtension
//
//  Created by 康凯 on 17/06/2017.
//  Copyright © 2017 康凯. All rights reserved.
//

import Foundation
import UIKit

// 设备
let is_iPad = UI_USER_INTERFACE_IDIOM() == .pad
let is_iPhone = UI_USER_INTERFACE_IDIOM() == .phone
let is_tv = UI_USER_INTERFACE_IDIOM() == .tv

let is_iPhone_4_orLess = (is_iPhone && kScreen_Max_Length < 568.0)
let is_iPhone_5_orLess = (is_iPhone && kScreen_Max_Length < 667.0)
let is_iPhone_7_orLess = (is_iPhone && kScreen_Max_Length < 736.0)
let is_iPhone_7P_orLess = (is_iPhone && kScreen_Max_Length == 736.0)
let is_iPhone_5_orOther = (is_iPhone && kScreen_Max_Length == 568.0)
let is_iPhone_7_orOther = (is_iPhone && kScreen_Max_Length == 667.0)

// 屏幕相关
let kScreen_Width = UIScreen.main.bounds.width
let kScreen_Height = UIScreen.main.bounds.height
let kScreen_Max_Length = (max(kScreen_Width, kScreen_Height))
let kScreen_Min_Length = (min(kScreen_Width, kScreen_Height))

let kScreen_Scale = UIScreen.main.scale
let kScreen_Size = UIScreen.main.bounds.size
let kStatusBar_Height = UIApplication.shared.statusBarFrame.height

// 版本号
let kSystem_Version = UIDevice.current.systemVersion
func kSystem_Version_LessThan(version: String) -> Bool {                // 是否小于某一版本
    return kSystem_Version.compare(version) == ComparisonResult.orderedAscending
}

// 拉伸图片
func kStretch_Image(imamge: UIImage, top: CGFloat, left: CGFloat, bottom: CFloat, right: CFloat) {
    _ = (kSystem_Version_LessThan(version: "6.0") ? imamge.stretchableImage(withLeftCapWidth: Int(left), topCapHeight: Int(top)) : imamge.resizableImage(withCapInsets: UIEdgeInsets.init(top: top, left: left, bottom: CGFloat(bottom), right: CGFloat(right)), resizingMode: .stretch))
}

func kStretch_Image(image:UIImage, edgeInsets: UIEdgeInsets) -> UIImage {
    return (kSystem_Version_LessThan(version: "6.0") ? image.stretchableImage(withLeftCapWidth: Int(edgeInsets.left), topCapHeight: Int(edgeInsets.top)) : image.resizableImage(withCapInsets: edgeInsets, resizingMode: .stretch))
}

// 获取temp
let kPath_Temp = NSTemporaryDirectory()
// 获取沙盒 Document
let kPath_Document = NSSearchPathForDirectoriesInDomains(.userDirectory, .userDomainMask, true).first
// 获取沙盒 Cache
let kPath_Cache = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first

		
